package com.aop;

import com.aop.annotation.BussinessAno;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * author: liubw
 * 抓取BussinessAo注解
 */
@Service
public class FindBussinessAnnoService {
    public FindBussinessAnnoService() {

    }
    public Map<String, String> init(String className, String methodName) throws ClassNotFoundException {
        Class<?> cls = Class.forName(className);
        Map<String, String> res = new HashMap<>();
        Method[] declaredMethods = cls.getMethods();
        for (Method declaredMethod : declaredMethods) {
            if (declaredMethod.isAnnotationPresent(BussinessAno.class) && declaredMethod.getName().equals(methodName)) {
                BussinessAno annotation = declaredMethod.getDeclaredAnnotation(BussinessAno.class);
                res.put("desc",annotation.value() + annotation.description());
                res.put("timeout",annotation.timeout());
            }
        }
        return res;
    }
}

